#include <stdio.h>
int arr[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int day = 0;
int year = 0;
int month = 0;
int i = 0;
int j = 0;

int get_day(int year, int month, int day)
{
	if(month == 1 | month == 2)
		{
			month += 12;
			--year;
		}		
	int week = -1;
	week = (day + 2 * month + 3 * (month + 1) / 5 + year + year / 4 -year / 100 +year / 400) % 7 + 1;
	return week;	// 输出-1为错误
}

void singleMonth()
{
	printf("请输入查询的年.月 >");
	scanf("%d.%d", &year, &month);
	int week_day = get_day(year, month, 1);
	printf("\tMon\tTus\tWed\tThu\tFri\tSat\tSun\n");
	for(i = 0; i < week_day; i++)
	{
		printf("\t");
	}
	if(year % 400 == 0)
	{
		arr[1] = 29;
		day = arr[month - 1];
	}
	else
	{
		day = arr[month - 1];
	}
	for(i=0,j=week_day; i < day; i++,j++)
	{
        printf("%d\t",i+1);
        if(j>=7)
		{
            printf("\n\t");
            j=0;
        }
    }
	putchar(10);
}

void wholeYear()
{
	month = 1;
	printf("请输入查询的年 >");
	scanf("%d", &year);
	//int week_day = get_day(year, month, 1);
	for(month = 1; month < 13; month++)
	{
        printf("\n%d月\n", month);		
        int week_day = get_day(year, month, 1);
        printf("\tMon\tTus\tWed\tThu\tFri\tSat\tSun\n");
        for(i = 0; i < week_day; i++)
        {
            printf("\t");
        }
        if(year % 400 == 0)
        {
            arr[1] = 29;
            day = arr[month - 1];
        }
        else
        {
            day = arr[month - 1];
        }
        for(i=0,j=week_day; i < day; i++,j++)
        {
            printf("%d\t",i+1);
            if(j>=7)
            {
                printf("\n\t");
                j=0;
            }
        }
        putchar(10);
	}
	putchar(10);
}
